function Character(index,belong){
	base(this,LSprite,[]);
	var self = this;
	self.hp = 100;
	self.isDie = false;
	self.attack = 20;
	self.action = null;
	self.belong = belong;
	self.mode = null;
	self.target = null;
	self.animes = [];
	self.direction = DIRECTION.DOWN;
	self.to = {x:0,y:0};
	self.setCoordinate(0,0);
	var list = LGlobal.divideCoordinate(512,512,8,8);
	self.data = [
		new LBitmapData(datalist[index+"-0"],0,0,64,64),
		new LBitmapData(datalist[index+"-1"],0,0,64,64),
		new LBitmapData(datalist[index+"-2"],0,0,64,64),
		new LBitmapData(datalist[index+"-3"],0,0,64,64)
	];
	var anime;
	for(var i=0;i<self.data.length;i++){
		anime = new LAnimation(self,self.data[i],list);
		anime.x = -32;
		anime.y = -45;
		anime.visible = false;
		anime.addEventListener(LEvent.COMPLETE,self.animeOver);
		self.animes.push(anime);
	}
	self.setAction(ACTION.STAND,self.direction);
	self.step = 1,self.stepindex = 0;
	self.animeIndex = 0;
	self.animeStep = 2;
	self.addEventListener(LEvent.ENTER_FRAME,self.onframe);
}
Character.prototype.onframe = function (self){
	if(self.stepindex++ < self.step)return;
	self.stepindex = 0;
	if(self.isDie){
		if(self.alpha > 0){
			self.alpha -= 0.1;
			if(self.alpha < 0)self.alpha = 0;
		}else{
			self.parent.removeChild(self);
		}
		return;
	}
	if(self.hp <= 0){
		self.setAction(ACTION.DIE,self.direction);
	}
	if(self.x == self.to.x && self.y == self.to.y && !self.target){
		self.setAction(ACTION.STAND,self.direction);
	}else{
		self.move();
	}
	self.anime.onframe();
}
Character.prototype.move = function (){
	var self = this;
	var mx = 0,my = 0,direction;
	if(self.x < self.to.x){
		mx = 1;
	}else if(self.x > self.to.x){
		mx = -1;
	}
	if(self.y < self.to.y){
		my = 1;
	}else if(self.y > self.to.y){
		my = -1;
	}
	if(mx == 0 && my == 0)return;
	if(mx == 0){
		if(my > 0){
			direction = DIRECTION.DOWN;
		}else if(my < 0){
			direction = DIRECTION.UP;
		}
	}else if(my == 0){
		if(mx > 0){
			direction = DIRECTION.RIGHT;
		}else if(mx < 0){
			direction = DIRECTION.LEFT;
		}
	}else if(mx > 0){
		if(my > 0){
			direction = DIRECTION.RIGHT_DOWN;
		}else if(my < 0){
			direction = DIRECTION.RIGHT_UP;
		}
	}else if(mx < 0){
		if(my > 0){
			direction = DIRECTION.LEFT_DOWN;
		}else if(my < 0){
			direction = DIRECTION.LEFT_UP;
		}
	}
	self.setAction(ACTION.MOVE,direction);
	self.x += mx;
	self.y += my;
	var query = (self.belong == BELONG.SELF)?selfQuery:enemyQuery;
	query.remove(self);
	query.add(self,self.x,self.y);
}
Character.prototype.setCoordinate = function (x,y){
	this.x = this.to.x = x;
	this.y = this.to.y = y;
}
Character.prototype.setAction = function (action,direction){
	var self = this;
	if(self.action !== action){
		var anime;
		for(var i=0;i<self.animes.length;i++){
			anime = self.animes[i];
			anime.visible = false;
			if(i == action){
				anime.visible = true;
				self.anime = anime;
				self.anime.setAction(self.direction);
			}
		}
		self.action = action;
	}
	if(self.direction !== direction){
		self.direction = direction;
		self.anime.setAction(self.direction);
	}
}
Character.prototype.animeOver = function (anime){
	var self = anime.parent;
	if(self.isDie)return;
	if(self.action == ACTION.DIE){
		anime.setAction(self.direction,7,0);
		self.isDie = true;
		return;
	}
	/*if(self.animeIndex++ < self.animeStep)return;
	self.animeIndex = 0;*/
	if(self.action == ACTION.ATTACK){
		if(!checkCanAttack(self)){
			self.setAction(ACTION.STAND,self.direction);
			return;
		}
		self.target.hp -= self.attack;
		if(self.target.hp <= 0){
			self.target.setAction(ACTION.DIE,self.target.direction);
			self.target.clear();
			self.target = null;
		}
	}else if(self.action == ACTION.STAND || self.action == ACTION.MOVE){
		if(self.target){
			if(self.target.hp > 0){
				self.to.x = self.target.x;
				self.to.y = self.target.y;
				if(self.target.x != self.x && self.target.y != self.y){
					if(Math.abs(self.target.y - self.y) > Math.abs(self.target.x - self.x)*1.5){
						self.to.x = self.x;
					}else if(Math.abs(self.target.x - self.x) > Math.abs(self.target.y - self.y)*1.5){
						self.to.y = self.y;
					}
				}
				if(checkCanAttack(self)){
					self.move();
					self.to.x = self.x;
					self.to.y = self.y;
					self.setAction(ACTION.ATTACK,self.direction);
					var chara = self;
					return;
				}
			}else{
				self.target = null;
			}
		}
		self.target = queryRandTarget(self);
		if(self.target == null && self.action == ACTION.MOVE){
			self.setAction(ACTION.STAND,self.direction);
		}
	}
}
Character.prototype.clear = function (){
	var self = this,index;
	if(self.belong == BELONG.SELF){
		selfQuery.remove(self);
	    index = selfList.indexOf(self);
	    if (index!=-1)selfList.splice(index, 1);
	}else{
		enemyQuery.remove(self);
	    index = enemyList.indexOf(self);
	    if (index!=-1)enemyList.splice(index, 1);
	}
}